<?php
/**
 * +-------------------------------------------------------------
 * |Caption:
 * +-------------------------------------------------------------
 * |Author: Lenny
 * +-------------------------------------------------------------
 * |Email:  1685964109@qq.com
 * +-------------------------------------------------------------
 * |Date:   2024-03-04 10:54
 * +-------------------------------------------------------------
 */

namespace storage;

use think\Validate;

class FileValidate extends Validate
{
    // 验证规则
    protected $rule = [
        // 图片文件: jpg,jpeg,png,bmp,gif
        // 文件大小: 2MB = (1024 * 1024 * 2) = 2097152 字节
        'image' => 'filesize:2097152|fileExt:jpg,jpeg,png,bmp,gif',

        // 视频文件: mp4
        // 文件大小: 10MB = (1024 * 1024 * 10) = 10485760 字节
        'video' => 'filesize:10485760|fileExt:mp4',
        'pdf'   => 'filesize:10485760|fileExt:pdf'
    ];

    // 错误提示信息
    protected $message = [
        'image.filesize' => '图片文件大小不能超出2MB',
        'image.fileExt'  => '图片文件扩展名有误',
        'video.filesize' => '视频文件大小不能超出10MB',
        'video.fileExt'  => '视频文件扩展名有误',
        'pdf.filesize'   => 'pdf文件大小不能超过10MB',
        'pdf.fileExt'    => '文件扩展名有误',
    ];

    // 验证场景
    protected $scene = [
        'image' => ['image'],
        'video' => ['video']
    ];
}